package net.xiduth.game.player.actions;

import net.xiduth.game.Animation;
import net.xiduth.game.World;
import net.xiduth.game.player.Player;
import net.xiduth.game.player.content.tasks.CompletedTasks;
import net.xiduth.game.player.content.tasks.Congrats;
import net.xiduth.utils.Utils;

public class Rest extends Action {

	private static int[][] REST_DEFS = { { 5713, 1549, 5748 },
			{ 11786, 1550, 11788 }, { 5713, 1551, 2921 }

	};

	private int index;

	@Override
	public boolean start(Player player) {
		if (!process(player))
			return false;
		index = Utils.random(REST_DEFS.length);
		player.setResting(true);
		player.setNextAnimation(new Animation(REST_DEFS[index][0]));
		player.getAppearence().setRenderEmote(REST_DEFS[index][1]);
		if (player.ToggleSystem == true) { 
			player.RestTask += 1;
			player.sm("[Weekly Task]: You have rested "+ player.RestTask +" out of 750 times.");
			CompletedTasks.checkCompletedTasks(player);
		}
		if (player.RestTask == 750) {
			player.RestTask = 755;
			Congrats.sendCongratsBoard(player);
			player.setSpins(player.getSpins() + 50);
			player.sm("You where awarded 50 SOF spins for completing this task.");
			World.sendWorldMessage("<img=6><col=FF000>"+ player.getDisplayName() +" has completed the Resting Task.", false);
		}
		return true;
	}

	@Override
	public boolean process(Player player) {
		if (player.getPoison().isPoisoned()) {
			player.getPackets().sendGameMessage(
					"You can't rest while you're poisoned.");
			return false;
		}
		if (player.getAttackedByDelay() + 10000 > Utils.currentTimeMillis()) {
			player.getPackets().sendGameMessage(
					"You can't rest until 10 seconds after the end of combat.");
			return false;
		}
		return true;
	}

	@Override
	public int processWithDelay(Player player) {
		return 0;
	}

	@Override
	public void stop(Player player) {
		player.setResting(false);
		player.setNextAnimation(new Animation(REST_DEFS[index][2]));
		player.getEmotesManager().setNextEmoteEnd();
		player.getAppearence().setRenderEmote(-1);
	}

}
